﻿#include "ServerCommand.h"
#include "../../../Utils/Utils.h"
#include "../../../Memory/GameData.h"

bool ServerCommand_onExecute(const fast_io::vector<std::u8string>& args) {
	if (GameData::getLocalPlayer() == nullptr) [[unlikely]]
		return true;
	const auto NetInstance = GameData::getRakNetInstance();
	auto ip = NetInstance->serverIp.getString();

	if (!ip.empty()) [[likely]] {
		
		auto port = NetInstance->serverPort;

		C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
										 u8"[Helium] ",
										 Utils::TextColor::RESET,
										 u8"IP: ",
										 ip,
										 u8"\nPort: ",
										 port,
										 u8"\nDNS to ip address:\n");


		fast_io::native_dns_file dnsfile(ip);
		for (auto ent : dnsfile) 
			C_GuiData::displayClientMessageC(to_ip_address(ent));

	} else
		C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
										 u8"[Helium] ",
										 Utils::TextColor::RESET,
										 u8"You're not playing on a server.");
	return true;
}

ICommand ServerCommand{
	u8"server",
	u8".server/ ip",
	{u8"Output server ip", u8"输出服务器ip", u8"輸出服務器ip", u8"出力サーバip"},
	{u8"ip"},
	fast_io::vector<aliasList_struct>{},  // If empty must use fast_io::vector<aliasList_struct>{}
	nullptr,
	&ServerCommand_onExecute};
